# Import libraries
import xarray as xr
import numpy as np
import pylab as plt
import cmocean as cm
# Import TrackEddy
from trackeddy.tracking import *
from trackeddy.plotfunc import *
# Load Data
filepath = '/g/data/ua8/CMEMS_SeaLevel/v4-0/2016/dt_global_allsat_phy_*.nc'
# Open netcdf Dataset.
dataset = xr.open_mfdataset(filepath,parallel=True)
# Load data into memory
sla=dataset.sla.isel(time=slice(0,2)).values
lon=dataset.longitude.values
lat=dataset.latitude.values
# Define area of study
areamap = np.array([[0,len(lon)],[0,len(lat)]]) # Global option
# Time and spatial filter
filters = {'time':{'type':None,'t':None,'t0':None,'value':None},
'spatial':{'type':'moving','window':50,'mode':'uniform'}}
# Mesoscale scaling
checkarea={'mesoscale':2*np.pi}
# Eddy definition criteria
preferences={'ellipse':0.85,'eccentricity':0.85,'gaussian':0.8}
# Levels to be analysed and to extract positive eddies from anomaly
levels_pos = {'max':np.nanmax(sla[0,:,:]),'min':0.01,'step':0.01}
# Levels to be analysed and to extract negative eddies from anomaly
levels_neg = {'max':np.nanmin(sla[0,:,:]),'min':-0.01,'step':-0.01}
# Warm core eddies identification
positive_eddies=analyseddyzt(sla,lon,lat,0,1,1,levels_pos,preferences=preferences
,areamap=areamap,areaparms=checkarea,filters=filters,timeanalysis='none'
,maskopt='contour',diagnostics=False,pprint=True)
0% [==========>]100% | Elapsed Time: 0 s | Estimated Time: 0 s | Info: Init time | 0% [==========>]100% | Elapsed Time: 419 s | Estimated Time: 419 s | Info: # of E 18280 ||
# Cold core eddies identification
negative_eddies=analyseddyzt(sla,lon,lat,0,1,1,levels_neg,preferences=preferences
,areamap=areamap,areaparms=checkarea,filters=filters,timeanalysis='none'
,maskopt='contour',diagnostics=False,pprint=True)
0% [==========>]100% | Elapsed Time: 0 s | Estimated Time: 0 s | Info: Init time | 0% [==========>]100% | Elapsed Time: 510 s | Estimated Time: 510 s | Info: # of E 19613 ||
Trackeddy is an algorithm which identifies and tracks eddies assuming that their outer most contours is well fitted by an ellipse (A. Fernandes and S. Nascimento, (2006))
The area of the eddy contour should be smaller than the first baroclinic Rossby Radius of Deformation (Mesoscale Scaling) defined as: \begin{equation} 2\pi L_r \end{equation} (Klocker, A., & Abernathey, R. (2014)).
To avoid the detection of meanders (jets), and due to the coherience of eddies, the eccentricity of the fitted ellipse eddies should be smaller than \begin{equation} \frac{b}{2a} \end{equation} which qualitatively corresponds to a semi-major axis two times larger than the semi-minor axis.
positive_eddy_field=reconstruct_syntetic(np.shape(sla),lon,lat,positive_eddies)
0% [==========>]100% | Elapsed Time: 32 s | Estimated Time: 32 s | Info: eddyn_1143 |
negative_eddy_field=reconstruct_syntetic(np.shape(sla),lon,lat,negative_eddies)
0% [==========>]100% | Elapsed Time: 33 s | Estimated Time: 33 s | Info: eddyn_1236 |
basemap_mplot(lon,lat,positive_eddy_field[0,:,:],title="Positive Eddies",projection='cyl',
lat_0=-90,lon_0=-180,resolution='c',vmin=-0.80,vmax=0.80,
cmap=cm.cm.balance,xan=1,yan=1,figsize=(5,2.5),fontsize=12,drawlinewidth=0.3)
plt.colorbar();
basemap_mplot(lon,lat,negative_eddy_field[0,:,:],title="Negative Eddies",projection='cyl',
lat_0=-90,lon_0=-180,resolution='c',vmin=-0.80,vmax=0.80,
cmap=cm.cm.balance,xan=1,yan=1,figsize=(5,2.5),fontsize=12,drawlinewidth=0.3)
plt.colorbar();
basemap_mplot(lon,lat,sla[0,:,:],
title="SLA",projection='cyl',
lat_0=-90,lon_0=-180,resolution='c',vmin=-0.80,vmax=0.80,
cmap=cm.cm.balance,xan=1,yan=1,figsize=(6,6),fontsize=12,drawlinewidth=0.3);
basemap_mplot(lon,lat,+negative_eddy_field[0,:,:]+positive_eddy_field[0,:,:],
title=["SLA","Reconstructed SSHa"],projection='cyl',
lat_0=-90,lon_0=-180,resolution='c',vmin=-0.80,vmax=0.80,
cmap=cm.cm.balance,xan=1,yan=1,figsize=(6,6),fontsize=12,drawlinewidth=0.3);
Global trends of transient kinetic energy from satellite observations between 1993-2018. Dots show regions where the trends are not significant according to the Pearson coefficient ($\sigma$=0.05).
from tcoasts import *
from dask.distributed import Client
c=Client()
c
Client
|
Cluster
|

folder='/g/data3/hh5/tmp/jm_eddy_lagrangian/mitgcm/run/'
contourfile='/g/data1a/v45/jm5970/github/ptracers/input_data/GoMCoastLine_nolagoon.xy'
distance=np.array([-450,-235,-90,-45,-15,0,15,45,90,235,450])

tac=tcoasts.TransportAlongCoast(folder,[-94,18],contourfile,distance=distance,length=50)
%%time
interp=tac.inter2vector(ufiles='U.*.nc',vfiles='V.*.nc',tracerfile='PTRACER01.*.nc')
/g/data1a/v45/jm5970/github/tcoasts/tcoasts/utils/decorators.py:11: Warning: Loading previous saved data.
warnings.warn('Loading previous saved data.', Warning)
CPU times: user 63 ms, sys: 330 ms, total: 393 ms Wall time: 890 ms
transport=tac.compute_transport()

f,ax=plt.subplots(figsize=(15,3),dpi=300)
#(transport.sum(dim={'depth','n'})/1e6).plot.line(x='time',ax=ax,linewidth=1)
for ii in range(len(transport.transect)):
ax.plot(transport.time,(transport/1e6).isel(transect=ii),label=str(distance[ii])+' km')
ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=12, mode="expand", borderaxespad=0.)
plt.ylabel('Transport [$Sv$]')
plt.grid()
plt.xlim(transport.time[0].values,transport.time[-1].values)
plt.ylim(-1.5,1.5)
plt.title('Total Transport',y=1.15,fontsize=13)
Text(0.5, 1.15, 'Total Transport')
f,ax=plt.subplots(figsize=(15,3),dpi=300)
#(transport.sum(dim={'depth','n'})/1e6).plot.line(x='time',ax=ax,linewidth=1)
scaled_transport=tac.mask_transport(0.01,method='greater')
for ii in range(len(scaled_transport.transect)):
ax.plot(scaled_transport.time,(scaled_transport/1e6).isel(transect=ii),label=str(distance[ii])+' km')
ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=12, mode="expand", borderaxespad=0.)
plt.ylabel('Transport [$Sv$]')
plt.grid()
plt.xlim(transport.time[0].values,transport.time[-1].values)
plt.title('Passive Tracer Transport [$C > 10\%$]',y=1.15,fontsize=13)
#plt.ylim(-1.5,1.5)
Text(0.5, 1.15, 'Passive Tracer Transport [$C > 10\\%$]')